import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service


class TestLogin(object):
    def test_account_does_not_exist(self):
        driver_path = "C:/Users/Lenovo/AppData/Local/Programs/Python/Python310/geckodriver.exe"
        service = Service(executable_path=driver_path)
        driver = webdriver.Firefox(service=service)
        driver.get("https://hmshop-test.itheima.net/")
        driver.maximize_window()
        driver.implicitly_wait(10)

        # 1、点击首页的"登录"链接，进入登录页面
        driver.find_element(By.LINK_TEXT, "登录").click()
        # 2、输入一个不存在的用户名
        driver.find_element(By.ID, "username").send_keys("13811110001")
        # 3、输入密码
        driver.find_element(By.ID, "password").send_keys("123456")
        # 4、输入验证码
        driver.find_element(By.ID, 'verify_code').send_keys("8888")
        # 5、点击登录按钮
        driver.find_element(By.NAME, "sbtbutton").click()
        # 6、获取错误提示信息
        msg = driver.find_element(By.CLASS_NAME, "layui-layer-content").text
        print("错误提示信息为：", msg)
        driver.quit()

    def test_wrong_password(self):
        driver_path = "C:/Users/Lenovo/AppData/Local/Programs/Python/Python310/geckodriver.exe"
        service = Service(executable_path=driver_path)
        driver = webdriver.Firefox(service=service)
        driver.get("https://hmshop-test.itheima.net/")
        driver.maximize_window()
        driver.implicitly_wait(10)
        # 1、点击首页的"登录"链接，进入登录页面
        driver.find_element(By.LINK_TEXT, '登录').click()
        # 2、输入用户名
        driver.find_element(By.ID, 'username').send_keys("13800001111")
        # 3、输入一个错误的密码
        driver.find_element(By.ID, 'password').send_keys("123456")
        # 4、输入验证码
        driver.find_element(By.ID, 'verify_code').send_keys("8888")
        # 5、点击登录按钮
        driver.find_element(By.NAME, 'sbtbutton').click()
        # 6、获取错误提示信息
        msg = driver.find_element(By.CLASS_NAME, 'layui-layer-content').text
        print("错误提示信息为：", msg)
        driver.quit()


if __name__ == '__main__':
    pytest.main(['-s', 'tpshop_login1.py'])